home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / zodiack.c < prev   
C/C++ Source or Header  |  2000-05-04  |  5KB  |  245 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13. unsigned char *zodiack_videoram2;
  14.  
  15. extern unsigned char *galaxian_attributesram;
  16. extern unsigned char *galaxian_bulletsram;
  17. extern size_t galaxian_bulletsram_size;
  18. extern int percuss_hardware;
  19.  
  20. static int flipscreen;
  21.  
  22. void zodiack_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  23. {
  24.     int i;
  25.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  26.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  27.  
  28.  
  29.     /* first, the character/sprite palette */
  30.     for (i = 0;i < Machine->drv->total_colors-1; i++)
  31.     {
  32.         int bit0,bit1,bit2;
  33.  
  34.         /* red component */
  35.         bit0 = (*color_prom >> 0) & 0x01;
  36.         bit1 = (*color_prom >> 1) & 0x01;
  37.         bit2 = (*color_prom >> 2) & 0x01;
  38.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  39.         /* green component */
  40.         bit0 = (*color_prom >> 3) & 0x01;
  41.         bit1 = (*color_prom >> 4) & 0x01;
  42.         bit2 = (*color_prom >> 5) & 0x01;
  43.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  44.         /* blue component */
  45.         bit0 = 0;
  46.         bit1 = (*color_prom >> 6) & 0x01;
  47.         bit2 = (*color_prom >> 7) & 0x01;
  48.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  49.  
  50.         color_prom++;
  51.     }
  52.  
  53.     /* white for bullets */
  54.     *(palette++) = 0xff;
  55.     *(palette++) = 0xff;
  56.     *(palette++) = 0xff;
  57.  
  58.  
  59.     for (i = 0;i < TOTAL_COLORS(0);i+=2)
  60.     {
  61.         COLOR(0,i  ) = (32 + (i / 2));
  62.         COLOR(0,i+1) = (40 + (i / 2));
  63.     }
  64.  
  65.     for (i = 0;i < TOTAL_COLORS(3);i++)
  66.     {
  67.         if ((i & 3) == 0)  COLOR(3,i) = 0;
  68.     }
  69.  
  70.     /* bullet */
  71.     COLOR(2, 0) = 0;
  72.     COLOR(2, 1) = 48;
  73. }
  74.  
  75.  
  76. WRITE_HANDLER( zodiac_flipscreen_w )
  77. {
  78.     if (flipscreen != (!data))
  79.     {
  80.         flipscreen = !data;
  81.  
  82.         memset(dirtybuffer, 1, videoram_size);
  83.     }
  84. }
  85.  
  86.  
  87. WRITE_HANDLER( zodiac_control_w )
  88. {
  89.     /* Bit 0-1 - coin counters */
  90.     coin_counter_w(0, data & 0x02);
  91.     coin_counter_w(1, data & 0x01);
  92.  
  93.     /* Bit 2 - ???? */
  94. }
  95.  
  96. /***************************************************************************
  97.  
  98.   Draw the game screen in the given osd_bitmap.
  99.   Do NOT call osd_update_display() from this function, it will be called by
  100.   the main emulation engine.
  101.  
  102. ***************************************************************************/
  103.  
  104. void zodiack_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  105. {
  106.     int offs;
  107.  
  108.  
  109.     /* draw the background characters */
  110.     for (offs = 0; offs < videoram_size; offs++)
  111.     {
  112.         int code,sx,sy,col;
  113.  
  114.  
  115.         if (!dirtybuffer[offs])  continue;
  116.  
  117.         dirtybuffer[offs] = 0;
  118.  
  119.  
  120.         sy = offs / 32;
  121.         sx = offs % 32;
  122.  
  123.         col = galaxian_attributesram[2 * sx + 1] & 0x07;
  124.  
  125.         if (flipscreen)
  126.         {
  127.             sx = 31 - sx;
  128.             sy = 31 - sy;
  129.         }
  130.  
  131.         code = videoram[offs];
  132.  
  133.         drawgfx(tmpbitmap,Machine->gfx[3],
  134.                 code,
  135.                 col,
  136.                 flipscreen, flipscreen,
  137.                 8*sx, 8*sy,
  138.                 0,TRANSPARENCY_NONE,0);
  139.     }
  140.  
  141.  
  142.     /* draw the foreground characters */
  143.     for (offs = 0; offs < videoram_size; offs++)
  144.     {
  145.         int code,sx,sy,col;
  146.  
  147.  
  148.         sy = offs / 32;
  149.         sx = offs % 32;
  150.  
  151.         col = (galaxian_attributesram[2 * sx + 1] >> 4) & 0x07;
  152.  
  153.         if (flipscreen)
  154.         {
  155.             sy = 31 - sy;
  156.             sx = 31 - sx;
  157.         }
  158.  
  159.         code = zodiack_videoram2[offs];
  160.  
  161.         drawgfx(bitmap,Machine->gfx[0],
  162.                 code,
  163.                 col,
  164.                 flipscreen, flipscreen,
  165.                 8*sx, 8*sy,
  166.                 &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  167.     }
  168.  
  169.  
  170.     /* copy the temporary bitmap to the screen */
  171.     {
  172.         int i, scroll[32];
  173.  
  174.  
  175.         if (flipscreen)
  176.         {
  177.             for (i = 0;i < 32;i++)
  178.             {
  179.                 scroll[31-i] = galaxian_attributesram[2 * i];
  180.             }
  181.         }
  182.         else
  183.         {
  184.             for (i = 0;i < 32;i++)
  185.             {
  186.                 scroll[i] = -galaxian_attributesram[2 * i];
  187.             }
  188.         }
  189.  
  190.         copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->drv->visible_area,TRANSPARENCY_COLOR,0);
  191.     }
  192.  
  193.  
  194.     /* draw the bullets */
  195.     for (offs = 0;offs < galaxian_bulletsram_size;offs += 4)
  196.     {
  197.         int x,y;
  198.  
  199.  
  200.         x = galaxian_bulletsram[offs + 3] + Machine->drv->gfxdecodeinfo[2].gfxlayout->width;
  201.         y = galaxian_bulletsram[offs + 1];
  202.  
  203.         if (!percuss_hardware)
  204.         {
  205.             y = 255 - y;
  206.         }
  207.  
  208.         drawgfx(bitmap,Machine->gfx[2],
  209.                 0,    /* this is just a dot, generated by the hardware */
  210.                 0,
  211.                 0,0,
  212.                 x,y,
  213.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  214.     }
  215.  
  216.  
  217.     /* draw the sprites */
  218.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  219.     {
  220.         int flipx,flipy,sx,sy,spritecode;
  221.  
  222.  
  223.         sx = 240 - spriteram[offs + 3];
  224.         sy = 240 - spriteram[offs];
  225.         flipx = !(spriteram[offs + 1] & 0x40);
  226.         flipy =   spriteram[offs + 1] & 0x80;
  227.         spritecode = spriteram[offs + 1] & 0x3f;
  228.  
  229.         if (percuss_hardware)
  230.         {
  231.             sy = 240 - sy;
  232.             flipy = !flipy;
  233.         }
  234.  
  235.         drawgfx(bitmap,Machine->gfx[1],
  236.                 spritecode,
  237.                 spriteram[offs + 2] & 0x07,
  238.                 flipx,flipy,
  239.                 sx,sy,
  240.                 //flipscreen[0] ? &spritevisibleareaflipx : &spritevisiblearea,TRANSPARENCY_PEN,0);
  241.                 //&spritevisiblearea,TRANSPARENCY_PEN,0);
  242.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  243.     }
  244. }
  245.